package com.likl.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.likl.dao.BookDao;
import com.likl.domain.Book;
import com.likl.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.HashMap;

/**
 * ClassName:springboot_study
 * Description:
 *
 * @Create: 2024/7/12 10:53
 * @author: likl
 * @e-mail: likl1102@foxmail.com
 * @QQ: 2514927731
 */
@Service
public class BookServiceImpl extends ServiceImpl<BookDao, Book> implements BookService {
    @Autowired
    private BookDao bookDao;

//    private HashMap<Integer, Book> cache = new HashMap<>();

//    @Override
//    public Book getById(Integer id) {
//        Book book = cache.get(id);
//        if (book == null) {
//            Book queryBook = bookDao.selectById(id);
//            cache.put(id, queryBook);
//            return queryBook;
//        }
//        return book;
//    }

    @Override
    @Cacheable(value = "cacheSpace",key = "#id")
    public Book getById(Integer id) {
        return bookDao.selectById(id);
    }
}
